package org.onionframework.persistence.dao.functions.rowsjoin;

import org.onionframework.persistence.dao.functions.RowsConcatFunction;

public class HSQLRowsConcatFunction implements RowsConcatFunction {

	@Override
	public String toSQL(String column, String separator) {
		StringBuilder sb = new StringBuilder();
		
		sb.append("rows_concat(").append(column).append(")");
		
		return sb.toString();
	}

    public static String rowsConcat(String in, Boolean flag,
                                  String[] register, Integer[] counter) {
        if (flag) {
            if (register[0] == null) {
                return null;
            }
            return register[0];
        }
        if (in == null) {
            return null;
        }
        if (register[0] == null) {
            register[0] = in;
            counter[0] = 1;
        } else {
            register[0] += "," + in;
            counter[0]++;
        }
        return null;
    }
}
